﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.IO;

namespace SpeakupUI
{
    [Serializable]
    class Settings
    {
        public String User = "user";
        public String Password = "password";
        public String School = "school";


        static readonly string DefaultFile = "settings.bin";

        public void Save(string fileName)
        {
            IFormatter formatter = new BinaryFormatter();
            using (FileStream s = File.Create(fileName))
            {
                formatter.Serialize(s, this);
            }
        }
        public void Save()
        {
            Save(DefaultFile);
        }
        public static Settings Load(string fileName)
        {
            IFormatter formatter = new BinaryFormatter();
            Settings settings = null;
            using (FileStream s = File.OpenRead(fileName))
            {
                settings = (Settings)formatter.Deserialize(s);
            }

            return settings;
        }
        public static Settings Load()
        {
            return Load(DefaultFile);
        }

    }
}
